﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace NotebookS2.Manufacturing.Transactions
{
    public partial class MfrCalendarSched : Form
    {
        public MfrCalendarSched()
        {
            InitializeComponent();
        }

        public string ConnectionString { get; set; }
        public string ActiveUserId { get; set; }

        public DataTable AppointmentsData { get; set; }

       
       

        void BindSchedules()
        {
            DataTable dt = new DataTable();
            SqlConnection oConnection = new SqlConnection();
            SqlCommand oCommand = new SqlCommand();
            SqlDataAdapter oAdapter = new SqlDataAdapter();

            oConnection.ConnectionString = this.ConnectionString;
            oConnection.Open();

            oCommand.Connection = oConnection;
            oCommand.CommandText = "SELECT * FROM OPRDSCHED";
            oAdapter.SelectCommand = oCommand;
            oAdapter.Fill(dt);

            this.AppointmentsData = dt;
            schedulerStorage1.Resources.DataSource = this.AppointmentsData;
            schedulerControl1.Storage = schedulerStorage1;
            schedulerControl1.Refresh();
            
            //schedulerStorage1.SetAppointmentId(schedulerControl1, "Id");
            oConnection.Close();
        }

        private void MfrCalendarSched_Load(object sender, EventArgs e)
        {
            schedulerControl1.Start = System.DateTime.Now;

            

            BindSchedules();
            
        }

        private void schedulerControl1_EditAppointmentFormShowing(object sender, DevExpress.XtraScheduler.AppointmentFormEventArgs e)
        {
            DevExpress.XtraScheduler.SchedulerControl scheduler = ((DevExpress.XtraScheduler.SchedulerControl)(sender));

            NotebookS2.Manufacturing.Transactions.CustomAppointmentForm form = new NotebookS2.Manufacturing.Transactions.CustomAppointmentForm(scheduler, e.Appointment, e.OpenRecurrenceForm);
            try
            {
                
                e.DialogResult = form.ShowDialog();
                e.Handled = true;
            }
            finally
            {
                form.Dispose();
            }

        }

        private void schedulerStorage1_AppointmentsChanged(object sender, DevExpress.XtraScheduler.PersistentObjectsEventArgs e)
        {
            
        }

        private void schedulerStorage1_AppointmentInserting(object sender, DevExpress.XtraScheduler.PersistentObjectCancelEventArgs e)
        {
            
        }
    }
}
